/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
 */
package td.pt.event;

import td.domain.StatisticalGrouping;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;

@SuppressWarnings("rawtypes")
public class ThoughtListingEvent<SG extends StatisticalGrouping> extends
		GwtEvent<ThoughtListingEvent.ThoughtListingHandler> {

	public static Type<ThoughtListingHandler> TYPE = new Type<ThoughtListingHandler>();
	private SG statsGrouping;
	private String titleString;

	public interface ThoughtListingHandler<SG extends StatisticalGrouping> extends
			EventHandler {
		void onNewGroupingListing(ThoughtListingEvent<SG> event);
	}

	public interface ThoughtListingHasHandlers<SG extends StatisticalGrouping>
			extends HasHandlers {
		HandlerRegistration addThoughtListingHandler(
				ThoughtListingHandler<SG> handler);
	}

	public ThoughtListingEvent(String statisticsTitleString, SG statsGrouping) {
		this.titleString = statisticsTitleString;
		this.statsGrouping = statsGrouping;
	}

	public SG getStatistics() {
		return statsGrouping;
	}

	public String geTitleString() {
		return titleString;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected void dispatch(ThoughtListingHandler handler) {
		handler.onNewGroupingListing(this);
	}

	@Override
	public Type<ThoughtListingHandler> getAssociatedType() {
		return TYPE;
	}

	public static Type<ThoughtListingHandler> getType() {
		return TYPE;
	}

	public static <SG extends StatisticalGrouping> void fire(
			HasHandlers source, String titleString, SG statsGrouping) {
		source.fireEvent(new ThoughtListingEvent<SG>(titleString, statsGrouping));
	}
}
